package club.terroir.server.util;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

public class MailSender {

	private static MailSender instance = new MailSender();
	
	public static MailSender getInstance() {
		return instance;
	}

	// ...
	public void sendMessage(String to, String from, String subject,String body) {
		Properties props = new Properties();
		Session session = Session.getDefaultInstance(props, null);
		String msgBody = body;
		try {
			Message msg = new javax.mail.internet.MimeMessage(session);
			msg.setFrom(new InternetAddress(from));
			msg.addRecipient(Message.RecipientType.TO, new javax.mail.internet.InternetAddress(to));
			msg.setSubject(subject);
			msg.setText(msgBody);
			Transport.send(msg);
		} catch (AddressException e) {
			e.printStackTrace();
		} catch (MessagingException e) {
			e.printStackTrace();
		}
	}
}
